<?php

 class Modelo_model extends CI_Model {

    function __construct(){
        parent::__construct();
    }

    function add($valores = null, $table = ''){
        $ids = array();
        for($x = 0; $x < count($valores); $x++){
            $this->db->insert($table, $valores[$x]);
            $ids[] = $this->db->insert_id();
        }
        return $ids;
        if($this->db->_error_message() != ''){
            log_message('error', $table.'.add: '.$this->db->_error_message());
        }
    }

    function delete($wheres = null, $table = ''){
        $rows = 0;
        foreach ($wheres as $key => $value){
            foreach ($value as $clave => $valor){
                $this->db->$clave($valor);
                $this->db->delete($table);
                $rows = $rows + $this->db->affected_rows();
            }
        }
        $response = array();
        $response[] = $rows;
        return $response;
        if($this->db->_error_message() != ''){
            log_message('error', $table.'.delete: '.$this->db->_error_message());
        }
    }

    function update($valores = null, $table = ''){
        $rows = 0;
        $wheres = 0;
        for($x = 0; $x < count($valores); $x++){
            foreach ($valores[$x] as $key => $value){
                if(is_numeric(strpos($key, 'where')) || is_numeric(strpos($key, 'like'))){
                    $this->db->$key($value);
                    $wheres = $wheres + 1;
                }
            }
            $this->db->update($table, array_slice($valores[$x], 0, count($valores[$x])-$wheres));
            $wheres = 0;
            $rows = $rows + $this->db->affected_rows();
        }
        $response = array();
        $response[] = $rows;
        return $response;
        if($this->db->_error_message() != ''){
            log_message('error', $table.'.update: '.$this->db->_error_message());
        }
    }

    function select($valores = null, $table = ''){
        for($x = 0; $x < count($valores); $x++){
            foreach ($valores[$x] as $key => $value){
                $this->db->$key($value);
            }
        }
        $query = $this->db->get($table);
        if($query){
            $response = array();
            foreach ($query->result_array() as $key => $value){
                $response[] = array($value, 'struct');
            }
            $response = array($response, 'array');
            return $response;
        }
        if($this->db->_error_message() != ''){
            log_message('error', $table.'.select: '.$this->db->_error_message());
        }
    }
}